package cn.bj.ykct;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class UseRequest
 */
@WebServlet("/useRequest")
public class UseRequest extends HttpServlet {

    /**
	 * 
	 */
	private static final long serialVersionUID = -6626516594408396203L;

	/**
     * @see HttpServlet#HttpServlet()
     */
    public UseRequest() {
        super();
    }

	/**
	 * @see Servlet#init(ServletConfig)
	 */
	public void init(ServletConfig config) throws ServletException {
	}

	/**
	 * @see Servlet#destroy()
	 */
	public void destroy() {
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter pw = response.getWriter();
		pw.append("Method: ").append(request.getMethod()).append("\r\n");
		pw.append("Params: ").append("\r\n");
		Map<String, String[]> paramMap = request.getParameterMap();
		for (Entry<String, String[]> paramEntry : paramMap.entrySet()) {
			pw.append(paramEntry.getKey()).append(" [");
			String[] values = paramEntry.getValue();
			int i = 0;
			for (String value : values) {
				if (i > 0) {
					pw.append(" ");
				}
				pw.append(value);
				i ++;
			}
			pw.append("]").append("\r\n");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
